package com.neusoft.nepm.utils;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zouran
 * createDate：2023/6/17  13:57
 */
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
    //放行目录
    private final String[] strings=new String[]
            {"/supervisor/saveSupervisor",
             "/supervisor/getSupervisorByIdByPass",
            "/supervisor/getSupervisorById",
            "/logon/captcha",
            "/logon/cheekCaptcha",
            "/doc.html",
            "/swagger-resources",
            "/statistics/listProvinceItemTotalStatis",
            "/statistics/getCityCoverage",
                    "/statistics/listAqiDistributeTotalStatis",
                    "/statistics/listAqiTrendTotalStatis",
                    "/statistics/getAqiCount",
                    "/statistics/getAqiGoodCount",
                    "/statistics/getProvinceCoverage",};

    // 注册 Sa-Token 拦截器，打开注解式鉴权功能
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。
        registry.addInterceptor(new SaInterceptor(handle -> {
                    StpUtil.checkLogin();
                }))
                .addPathPatterns("/**")
                .excludePathPatterns(strings);
    }
}
